How your code travels from a simple HTML file to a dynamic interactive application.
This isn't just a simple mix of HTML and CSS. To make the engine roar, you must first construct the environment using the terminal commands we mastered. Build the structure first, or the code will have nowhere to live.
If you already know, then you can skip this, scroll down and learn more.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>React App</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
#root div.
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.jsx'
import './index.css'
ReactDOM.createRoot(
document.getElementById('root')
).render(
<React.StrictMode>
<App />
</React.StrictMode>
)
#root, and renders your App component inside it.
import Navbar from './Navbar'
import Home from './Home'
function App() {
return (
<div class="app">
<Navbar />
<main>
<Home />
</main>
</div>
)}
export default App
Don't throw everything in src/. Group your UI into dedicated folders so you can find them instantly.
// Location: src/components/layout/Header.jsx
export default function Header() {
return (
<header>
<h1>My Website</h1>
</header>
)
}
Now, go to App.jsx and call it:
import Header from './components/layout/Header'